package com.heqq.zixi;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * @program: TestSelenium
 * @description: aa
 * @author: heqq
 * @create: 2018-09-18 16:39
 **/
public class A {

    @Test
    public void actionTest(){


        WebDriver driver = new ChromeDriver();

        //智能等待10s
        driver.manage().timeouts().pageLoadTimeout(10,TimeUnit.SECONDS);
        driver.get("http://www.baidu.com");
        By inputBox = By.id("kw");
        By searchButton = By.id("su");
        //实例化Actions
        Actions actions = new Actions(driver);
        //通过actions模拟键盘使用perform方法输入关键字heqq到输入框
        actions.sendKeys(driver.findElement(inputBox),"heqq").perform();
        //模拟鼠标移动到按钮
        actions.moveToElement(driver.findElement(searchButton)).perform();
        //点击操作
        actions.click().perform();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        driver.quit();
    }
}
